<?php

class Formation extends Zend_Db_Table_Abstract {
    protected $_name = "formations";
    private $dbAdapter;

    public function init() {
        $this->dbAdapter = Zend_Db_Table::getDefaultAdapter();
        $this->dbAdapter->setFetchMode(Zend_Db::FETCH_OBJ);
    }

     public function GetFormation($squad_id) {
        try {
            return $this->dbAdapter->fetchAll($this->select()->where('squad_id=?',$squad_id));
        } catch (Zend_Exception $e) {
            echo "Error message: " . $e->getMessage() . "\n";
            exit;
        }
    }

    public function AddPlayer($player_id, $position_id, $squad_id){
        $data = array(
            'player_id' => $player_id,
            'position_id' => $position_id,
            'squad_id' => $squad_id,
        );
        try{
            parent::insert($data);
        } catch (Zend_Exception $e) {
            echo "Error message: " . $e->getMessage() . "\n";
            exit;
        }
    }

}

